{% extends 'base.html' %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>章节管理</h2>
        <a href="{% url 'core:chapter_create' %}" class="btn btn-primary"><i class="bi bi-plus-circle me-2"></i>添加章节</a>
    </div>

    {% if chapters %} 
    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-striped table-hover">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>章节名称</th>
                            <th>学科</th>
                            <th>描述</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for chapter in chapters %}
                        <tr>
                            <td>{{ chapter.order }}</td>
                            <td>{{ chapter.name }}</td>
                            <td>{{ chapter.subject.name }}</td>
                            <td>{{ chapter.description|truncatechars:50 }}</td>
                            <td>
                                <div class="btn-group" role="group">
                                <a href="{% url 'core:knowledge_point_list' chapter.id %}" class="btn btn-sm btn-outline-info"><i class="bi bi-book me-1"></i>知识点</a>
                                <a href="{% url 'core:chapter_update' chapter.id %}" class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil me-1"></i>编辑</a>
                                <a href="{% url 'core:chapter_delete' chapter.id %}" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash me-1"></i>删除</a>
                            </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    {% else %}
    <div class="alert alert-info">
        暂无章节数据，请点击上方"添加章节"按钮创建新章节。
    </div>
    {% endif %}
</div>
{% endblock %}